package ren.kane.phoenix.thread;

/**
 * @author renrk(1275) on 2019-08-15 11:01 AM
 **/
public class YieldTest {
    public static void main(String[] args) {
        Thread t1 = new ThreadC("t1");
        Thread t2 = new ThreadC("t2");
        t1.start();
        t2.start();
    }
}

class ThreadC extends Thread {
    public ThreadC(String name) {
        super(name);
    }

    public synchronized void run() {
        for (int i = 0; i < 10; i++) {
            System.out.printf("%s [%d]:%d\n", this.getName(), this.getPriority(), i);
            // i整除4时，调用yield
            if (i % 4 == 0)
                Thread.yield();
        }
    }
}